package me.moscrop.RootCommand.commands;

import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Player;
import me.moscrop.RootCommand.utilities.Chat;
import me.moscrop.RootCommand.utilities.Utility;


public class Spawnmob {

	public static boolean mob(CommandSender sender, Command command, String label, String[] args) {
		
		Player player = (Player) sender;
		final Location loc = player.getTargetBlock(null, 50).getLocation();
		
		if (args.length < 1) return false;

		CreatureType mob = CreatureType.fromName(Character.toUpperCase(args[0].charAt(0)) + args[0].substring(1));
		
		if (mob == null) {
			sender.sendMessage("Syntax error");
			return false;
		}
		
		int amount = 1;
        if (args.length > 1) amount = Integer.parseInt(args[1]);        
        amount = (amount < 250) ?  amount : 250;
        		
        for (int i = 0; i < amount; i++) {
        	player.getWorld().spawnCreature(Utility.getSafeLocationAt(loc), mob);
        }
     
        Chat.message(player, "spawned "+ amount + " " + args[0]);	
        
        
        return true;
               		
	}
	
	
	
}
